testsuite: Add a test for a Firefox issue
authorBenjamin Otte <otte@redhat.com>
Tue, 18 Feb 2014 12:48:13 +0000 (13:48 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 20 Feb 2014 01:10:07 +0000 (02:10 +0100)
When creating a style context, the CSS for the theme might not be
loaded. If it is, this test will succeed.

https://bugzilla.redhat.com/show_bug.cgi?id=1064922
https://bugzilla.mozilla.org/show_bug.cgi?id=972382

testsuite/gtk/Makefile.am
testsuite/gtk/firefox-stylecontext.c [new file with mode: 0644]

index 077b4f3b108ae216a695c93f5fb6fcc8ae2a8e7f..d5a1bcb479cfa31031bd53485c3fa2727da7b3a7 100644 (file)
@@ -36,6 +36,7 @@ TEST_PROGS +=                         \
        defaultvalue            \
        entry                   \
        expander                \
+       firefox-stylecontext    \
        floating                \
        grid                    \
        gtkmenu                 \
diff --git a/testsuite/gtk/firefox-stylecontext.c b/testsuite/gtk/firefox-stylecontext.c
new file mode 100644 (file)
index 0000000..0e5ce78
--- /dev/null
@@ -0,0 +1,66 @@
+#include <gtk/gtk.h>
+
+static void
+test_init_of_theme (void)
+{
+  GtkStyleContext *context;
+  GtkCssProvider *provider;
+  GtkWidgetPath *path;
+  GdkRGBA before, after;
+  char *css;
+
+  /* Test that a style context actually uses the theme loaded for the 
+   * screen it is using. If no screen is set, it's the default one.
+   */
+  context = gtk_style_context_new ();
+  path = gtk_widget_path_new ();
+
+  /* Set a path that will have a color set.
+   * (This could actually fail if style classes change, so if this test
+   *  fails, make sure to have this path represent something sane.)
+   */
+  gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
+  gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_BACKGROUND);
+  gtk_style_context_set_path (context, path);
+  gtk_widget_path_free (path);
+
+  /* Get the color. This should be initialized by the theme and not be
+   * the default. */
+  gtk_style_context_get_color (context, 0, &before);
+
+  /* Add a style that sets a different color for this widget.
+   * This style has a higher priority than fallback, but a lower 
+   * priority than the theme. */
+  css = g_strdup_printf (".background { color: %s; }",
+                         before.alpha < 0.5 ? "black" : "transparent");
+  provider = gtk_css_provider_new ();
+  gtk_css_provider_load_from_data (provider, css, -1, NULL);
+  gtk_style_context_add_provider (context,
+                                  GTK_STYLE_PROVIDER (provider),
+                                  GTK_STYLE_PROVIDER_PRIORITY_FALLBACK + 1);
+  g_object_unref (provider);
+
+  /* Get the color again. */
+  gtk_style_context_get_color (context, 0, &after);
+
+  /* Because the style we added does not influence the color,
+   * the before and after colors should be identical. */
+  g_assert (gdk_rgba_equal (&before, &after));
+
+  g_object_unref (context);
+}
+
+int
+main (int argc, char *argv[])
+{
+  /* If gdk_init() is called before gtk_init() the GTK code takes
+   * a different path (why?)
+   */
+  gdk_init (NULL, NULL);
+  gtk_init (NULL, NULL);
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/style/init_of_theme", test_init_of_theme);
+
+  return g_test_run ();
+}